package com.hcms.admin.dto;

import cn.hutool.core.bean.BeanUtil;
import com.hcms.common.util.TreeNode;
import com.hcms.mybatis.entity.SysMenu;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;
import java.util.List;

@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class SysMenuRouteResponse implements Serializable, TreeNode<SysMenuRouteResponse, Long> {

    @Data
    @Builder
    @NoArgsConstructor
    @AllArgsConstructor
    static class Meta implements Serializable {

        private String title;

        private String icon;

        private Integer hidden;

        private Integer alwaysShow;

        private String perms;

        private Integer keepAlive;

    }

    private Long id;

    private Long parentId;

    private String path;

    private String component;

    private String name;

    private String redirect;

    private Meta meta;

    private Integer sort;

    private List<SysMenuRouteResponse> children;

    public SysMenuRouteResponse(SysMenu menu) {
        BeanUtil.copyProperties(menu, this);
        Meta metaData = Meta.builder()
                .title(menu.getMetaTitle())
                .icon(menu.getMetaIcon())
                .hidden(menu.getMetaHidden())
                .alwaysShow(menu.getMetaAlwaysShow())
                .perms(menu.getMetaPerms())
                .keepAlive(menu.getMetaKeepAlive())
                .build();
        this.setMeta(metaData);
    }
}
